package cn.xz.hfsk.adapter

import android.widget.ImageView
import androidx.core.content.ContextCompat
import cn.xz.hfsk.R
import cn.xz.hfsk.base.BaseApplication
import cn.xz.hfsk.bean.DeviceList
import cn.xz.hfsk.widgets.AutoScaleTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 设备列表适配器*/
class DeviceCAdapter : BaseQuickAdapter<DeviceList, BaseViewHolder>(R.layout.item_device_c) {

    override fun convert(holder: BaseViewHolder, item: DeviceList) {

        val tvDevice = holder.getView<AutoScaleTextView>(R.id.tv_device_c)
        tvDevice.post {
            tvDevice.text = item.name.toString()
        }

        var ivDeviceItemImg = holder.getView<ImageView>(R.id.iv_device_item_img)
        //显示不同的图标
        when(item.deviceType){
            2,3,9,11,13-> {
                ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_zj))
            }
            4,5,10->{
                ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_tyy))
            }
            8->{

            }
            else->{
                ivDeviceItemImg.setImageDrawable(ContextCompat.getDrawable(BaseApplication.getContext(),R.drawable.bg_device_item_pjp))
            }
        }
        //是否已经开启
        ivDeviceItemImg.isSelected = item.opening

    }
}